package com.maoyongjian.dome1.controller;

import com.maoyongjian.dome1.entity.Manager;
import com.maoyongjian.dome1.service.ManagerService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@Slf4j
@Controller
public class ManagerController {
    @Autowired
    private ManagerService managerService;
    @GetMapping("login")
    public String login(){
        return "login";
    }
    @PostMapping("login")
    public String login(String account, String password, Model model, HttpSession session){
        log.debug("account:{},passwprd:{}",account,password);
        Manager manager = managerService.login(account, password);
        if (manager !=null){
            //登录成功之后，将登录的信息存储到Session中
            session.setAttribute("manager",manager);
            return "index";
        }else {
            //将数据存储到了请求作用域 HttpServletRequest
            model.addAttribute("msg","账号或密码不正确");
            return "login";
        }
    }
    @GetMapping("manager/add")
    public String add(){
        return "manager_add";
    }
    @PostMapping("manager/add")
    public String add(String account,String password){
        return "ok";
    }
}
